$(function() {
        var refund_form = $("#refund_form");
        var refund_datagrid = $("#refund_datagrid");
        var refund_dialog = $("#refund_dialog");
    //begin列表信息
    refund_datagrid.datagrid({
        url: "/refund/list",
        columns: [[
            {field: "xxx", checkbox: 'true'},
            {field: "id", title: "编号", width: 100,hidden:true},
            {field: "refundName", title: "学员姓名", width: 100 ,},
            {field: "refunddate", title: "退款时间", width: 100},

            {field: "leavestudent2", title: "退款金额", width: 100 ,formatter:function (value,row,index) {
                return row.leavestudent.refundAmount;
            }},

            {field: "grade", title: "班级", width: 100 ,formatter:function (value,row,index) {
                if (value){

                    return value.name;
                }
            }},
            {field: "refunduser", title: "退款人", width: 100 ,formatter:function (value,row,index) {
                if (value){

                    return value.username;
                }
            }},
            {field: "inputuser", title: "录入人", width: 100 ,formatter:function (value,row,index) {
                if (value){

                    return value.username;
                }
            }},
            /*{field: "payment", title: "支付方式", width: 100 ,formatter:function (value,row,index) {
                if (value){

                    return value.username;
                }
            }},
            {field: "invoices", title: "单据号", width: 100},*/

            {field: "leavestudent3", title: "退款原因", width: 100 ,formatter:function (value,row,index) {
                return row.leavestudent.leavereasion;
            }},
            {field: "auditor", title: "审核人", width: 100 ,formatter:function (value,row,index) {
                if (value){

                return value.username;
                }
            }},
            {field: "refundamountstate", title: "审核转态", width: 100 ,formatter:function (value,row,index) {
                if(value == 0){
                    return '<font color="red">审核中</font>';
                }else if(value == 1){
                    return '<font color="green">审核通过</font>';
                }
            }}
        ]],
        fit: true,
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        striped: true,
        pageNumber:1,
        pageSize:10,
        pageList:[3,5,10,20],
        toolbar: "#refund_tb"
    });
    //end列表信息

    //begin添加/编辑对话框
    refund_dialog.dialog({
        width: 400,
        height:400,
        buttons: "#refund_bb",
        closed: true
    });
    //end添加/编辑对话框

    //begin处理功能方法的对象
    var obj = {


        //begin查看按钮
        watch: function () {
            refund_form.form("clear");
            refund_dialog.dialog("setTitle", "退款查看");
            var row = refund_datagrid.datagrid("getSelected");
            console.log(row);
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $("#refund_form :input").prop("readonly" ,true);
            if(row){
                row["leavestudent.refundAmount"] = row.leavestudent.refundAmount;
                row["grade.name"] = row.grade.name;
                row["refunduser.username"] = row.refunduser.username;
                row["inputuser.username"] = row.inputuser.username;
                row["inputuser.username"] = row.inputuser.username;
                row["leavestudent.leavereasion"] = row.leavestudent.leavereasion;
                row["auditor.username"] = row.auditor.username;
            }
            refund_form.form("load", row);
            refund_dialog.dialog("open");
            refund_form.find("input").attr("readonly",true);
        },
        //end查看按钮


        //begin 审核按钮
        changeState: function (){
            var row = refund_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $.messager.confirm('审核确认','想好后请点击确认？',function(r){
                if (r){
                    var url = "/refund/changeState?id="+row.id;
                    $.get(url, function(data){

                        if (!data.success) {
                            $.messager.alert('温馨提示', data.msg);
                        } else {
                            $.messager.alert('温馨提示', "操作成功!");

                            refund_datagrid.datagrid("reload");
                        }
                    });
                }
            });

        },
        //end 审核按钮


        // 学员高级查询操作
        query: function() {
            var gradeId= $("#gradeId").textbox("getValue");
            var beginDate= $("#beginDate").textbox("getValue");
            var endDate= $("#endDate").textbox("getValue");
            refund_datagrid.datagrid("load",{
                gradeId:gradeId,
                beginDate:beginDate,
                endDate:endDate
            });
        },
        // 学员高级查询操作 end

        //begin刷新按钮
        reload:function (){
            refund_datagrid.datagrid("reload")
        },
        //end刷新按钮

        //begin取消按钮
        cancel: function () {
            refund_dialog.dialog("close");
        },
        //end取消按钮
    };
    //end处理功能方法的对象

    //begin处理功能方法对象,实际调用方法
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        obj[cmd]();
    });
    //end处理功能方法对象,实际调用方法

});